import request from '../httpRequest'
import type { IResponse, IResWithPage } from '../../types/api'

export interface UpdateUserInfoRequest {
  username?: string;
  phone?: string;
  avatar?: string;
}

export interface UserExamsParams {
  page?: number;
  pageSize?: number;
  status?: string;
}

export interface UserExamRecordsParams {
  page?: number;
  pageSize?: number;
}

export const userApi = {
  // 获取用户信息
  getUserInfo(): Promise<IResponse<any>> {
    return request.get('/user/detail')
  },

  // 更新用户信息
  updateUserInfo(data: UpdateUserInfoRequest): Promise<IResponse<null>> {
    return request.post('/user/update', data)
  },

  // 获取用户的考试列表
  getUserExams(params: UserExamsParams): Promise<IResWithPage<any>> {
    return request.get('/user/exams', { params })
  },

  // 获取用户的考试记录
  getUserExamRecords(params: UserExamRecordsParams): Promise<IResWithPage<any>> {
    return request.get('/user/exam-records', { params })
  }
}
